﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AdoHelper
{
    [Serializable]
    public class DeleteBuilder
    {
        private int? top = null;
        public int? Top
        {
            get { return top; }
            set { top = value; }
        }

        private string tableName = "";
        public string TableName
        {
            get { return tableName; }
            set { tableName = value; }
        }

        private FromClause from = new FromClause();
        public FromClause From
        {
            get { return from; }
        }
        
        private WhereClause where = new WhereClause();
        public WhereClause Where
        {
            get { return where; }
            set { where = value; }
        }
        
        public string Statement
        {
            get
            {
                string s = "DELETE ";
                if (this.top.HasValue)
                {
                    s += " TOP (" + this.top.Value + ") ";
                }
                s+="FROM " + this.tableName + "\r\n";
                if (this.from.ToString() != "")
                {
                    s += "FROM " + this.from.ToString()+"\r\n";
                }
                if (this.where.ToString() != "")
                {
                    s += "WHERE " + this.where.ToString()+"\r\n";
                }
                return s;
            }
        }

        public void Reset()
        {
            this.top = null;
            this.tableName = "";
            this.from.Clear();
            this.where.Clear();
        }

        public override string ToString()
        {
            return this.Statement;
        }


    }
}
